﻿
Namespace Compiler.Semantic

    Public Class ConstructedTypeReference
        Inherits TypeReference

        Public Sub New(ByVal genericType As TypeReference, ByVal typeArgs As TypeReference())
            Debug.Assert(genericType IsNot Nothing AndAlso typeArgs IsNot Nothing)
            m_genericType = genericType
            m_typeArguments = typeArgs
        End Sub

        Private m_genericType As TypeReference
        Public Property GenericType() As TypeReference
            Get
                Return m_genericType
            End Get
            Set(ByVal value As TypeReference)
                m_genericType = value
            End Set
        End Property

        Private m_typeArguments As TypeReference()
        Public Property TypeArguments() As TypeReference()
            Get
                Return m_typeArguments
            End Get
            Set(ByVal value As TypeReference())
                m_typeArguments = value
            End Set
        End Property

        Public Overrides Function GetReflectionType() As System.Type
            Dim typeArgumentArray As Type() = _
                Array.ConvertAll(Of TypeReference, Type)(m_typeArguments, Function(tb) tb.GetReflectionType)

            Return GenericType.GetReflectionType().MakeGenericType(typeArgumentArray)
        End Function
    End Class
End Namespace